package backend.project.gym_management.controller;

import backend.project.gym_management.pojo.dto.CourseIntroDTO;
import backend.project.gym_management.service.CourseService;
import backend.project.gym_management.pojo.entity.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courses")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping
    public List<Course> getAllCourses() {
        return courseService.getAllCourses();
    }

    @GetMapping("/{cid}/intro")
    public ResponseEntity<CourseIntroDTO> getCourseIntro(@PathVariable Long cid) {
        CourseIntroDTO intro = courseService.getCourseIntro(cid);
        if (intro == null) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(intro);
    }
}
